package com.crayfish.quduo.presenter;

import com.crayfish.quduo.base.RxPresenter;
import com.crayfish.quduo.model.NewsBean;
import com.crayfish.quduo.presenter.contract.MyNewsContract;

import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.datatype.BmobQueryResult;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SQLQueryListener;

/**
 * 作者：crayfish(徐杰)
 * 描述：
 * Created by crayfish on 2017/3/30.
 */
public class MyNewsPresenter extends RxPresenter<MyNewsContract.View> implements MyNewsContract.Presenter{

    public MyNewsPresenter(){

    }
    @Override
    public void getMyNews(String userid) {
        String SQL = "select * from news";
        BmobQuery<NewsBean> query = new BmobQuery<>();
        query.addWhereEqualTo("userid",userid);
        query.doSQLQuery(SQL, new SQLQueryListener<NewsBean>() {
            @Override
            public void done(BmobQueryResult<NewsBean> bmobQueryResult, BmobException e) {
                if(e == null){
                    mView.showMyNews(bmobQueryResult.getResults());
                }else{
                    mView.showError("查询数据失败");
                }
            }
        });
    }
}
